<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>关于三种元素隐藏方式比较</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .easter_egg {
            width: 100px;
            height: 100px;
            position: absolute;
            bottom: 0px;
            right: 0px;
            opacity: 0;
            text-align: center;
            line-height: 100px;
        }
        .easter_egg:active {
            opacity: 1;
        }

        .container {
            background-color: grey;
        }

        .box0,.box1,.box2,.box3 {
            width: 200px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            margin: 50px auto;
        }

        .box0 {
            background-color: skyblue;
        }

        .box1 {
            background-color: yellow;
            /* display: none; */
        }

        .box2 {
            background-color: blue;
            /* opacity: 0; */
        }

        .box3 {
            background-color: orange;
            visibility: hidden;
        }

        /* .container:hover >.box3 {
            visibility: visible;
        } */
        /* .box2:hover {
            opacity: 1;
        } */
        .display_son {
            display: none;
        }

        .opacity_son {
            opacity: 0;
        }

        .visibility_son {
            /* visibility: visible; */
        }

        /* 当在表格元素中使用时，此值可删除一行或一列，但是它不会影响表格的布局 */
        table .coll {
            /* visibility: collapse; */
        }
    </style>
</head>

<body>
    <div class="easter_egg">点我啊</div>
    <div class="container">
        <div class="box0">.)_(.</div>

        <div class="box1">
            <span>display:none</span>
            <div class="display_son">display子元素</div>
        </div>

        <div class="box2">
            <span>opacity:0</span>
            <div class="opacity_son">opacity子元素</div>
        </div>

        <div class="box3">
            <span>visibility: hidden</span>
            <div class="visibility_son">visibility子元素</div>
        </div>
        <div class="box0">.)_(.</div>
        <div>
            <table border="1">
                <tr>
                    <td>Adams</td>
                    <td>John</td>
                </tr>
                <tr class="coll">
                    <td>Bush</td>
                    <td>George</td>
                </tr>
            </table>
        </div>
    </div>
    <script>
        var contain = document.querySelector('.container');
        var containDiv = document.querySelectorAll('.container div');
        contain.onclick = function () {
            contain.setAttribute('style', 'background-color:grey');
        }
        containDiv.forEach(function (el) {
            el.onclick = function () {
                alert(el.innerText);
            }
        })
        var easter_egg = document.querySelector('.easter_egg');
        var flag = false;
        easter_egg.onclick = function () {
            flag = !flag;
            flag ?
                contain.setAttribute('style', 'background-color:blue') :
                contain.setAttribute('style', 'background-color:red')
        }

    </script>
</body>

</html>